package com.nzw.service.impl.commodity;

import com.nzw.pojo.commodity.CommodityType;
import com.nzw.service.commodity.CommodityTypeService;
import com.nzw.service.impl.common.BaseServiceImpl;
import com.nzw.vo.common.HttpResult;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 18573 on 2018/9/14.
 */

@Service
public class CommodityTypeServiceImpl extends BaseServiceImpl implements CommodityTypeService {

    @Override
    public CommodityType getCommodityTypeById(Long id) {

        return getEntityById(id,CommodityType.class);
    }


    @Override
    public HttpResult addCommodityType(CommodityType commodityType) {

        return new HttpResult(HttpResult.OK, addEntity(commodityType));
    }

    @Override
    public HttpResult deleteCommodityTypeById(Long id) {

        CommodityType type = getEntityById(id,CommodityType.class);
        type.setDel(true);
        return new HttpResult(HttpResult.OK,updateEntityValues(type));
    }

    @Override
    public HttpResult updateCommodityType(CommodityType type) {

        return new HttpResult(HttpResult.OK,updateEntityValues(type));
    }

    

    @Override
    public HttpResult getCommodityTypeByParentId(Long parentId) {
        Map<String,Object> map = new HashMap<>();
        map.put("del",false);
        map.put("parentId",parentId);
        List<CommodityType> list = getEntitiesBySort(CommodityType.class,map,"sort",true);

        return new HttpResult(HttpResult.OK,list);
    }
}
